package com.dict.mybatis.lab;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;


@SpringBootApplication
@MapperScan("com.dict.mybatis.lab.mapper")
public class App {
    private static final Logger logger = LoggerFactory.getLogger(App.class);

    public static void main(String[] args) throws UnknownHostException {
        SpringApplication app = new SpringApplication(App.class);
        ConfigurableApplicationContext application = app.run(args);
        Environment env = application.getEnvironment();
        String tips =
                "----------------------------------------------------------\n" +
                        "Application %s is running! Access URLs:\n" +
                        "Local: http://localhost:%s\n" +
                        "External: 	http://%s:%s\n" +
                        "Doc: 	http://%s:%s/doc.html\n" +
                        "----------------------------------------------------------\n";

        logger.info(String.format(tips,
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"),
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"),
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port")));
    }

}